package initial;

public class StaticAndDynamicInitializeDemo {

    public static void main(String[] args) {
        String s1 = "hello"; //在字符串静态常量池中开辟空间
        String s2 = "hello"; //字符串静态常量池中该字面常量如果存在，则无须创建新对象。
        String s3 = new String("hello"); //在堆内存中开辟新空间
        String s4 = new String("hello".getBytes());//在堆内存中开辟新空间
        String s5 = new String("hello");//在堆内存中开辟新空间

        System.out.println(s1.equals(s2));
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s3));
        System.out.println(s1 == s3);
        System.out.println(s3.equals(s4));
        System.out.println(s3 == s4);
        System.out.println(s3.equals(s5));
        System.out.println(s3 == s5);
    }
}
